<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增固定资产信息')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-assets-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产编号：</label>
            <div class="col-sm-8">
                <input name="assetNumber" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产名称：</label>
            <div class="col-sm-8">
                <input name="assetName" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产类型：</label>
            <div class="col-sm-8">
                <select name="assetType" class="form-control " th:with="type=${@dict.getType('asset_type')}"
                        required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">分类：</label>
            <div class="col-sm-8">
                <select name="assetCategory" class="form-control " th:with="type=${@dict.getType('asset_category')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">资产品牌：</label>
            <div class="col-sm-8">
                <select name="assetBrand" class="form-control " th:with="type=${@dict.getType('asset_brand')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">供应商：</label>
            <div class="col-sm-8">
                <select name="supplier" class="form-control " th:with="type=${@dict.getType('asset_supplier')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">资产型号：</label>
            <div class="col-sm-8">
                <input name="assetModel" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产购置日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="purchaseDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">资产购置价值：</label>
            <div class="col-sm-8">
                <input name="purchaseValue" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">质保日期：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="warrantyDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">资产位置：</label>
            <div class="col-sm-8">
                <input name="location" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">IP地址：</label>
            <div class="col-sm-8">
                <input name="ipAddress" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">SN号：</label>
            <div class="col-sm-8">
                <input name="snNumber" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">MAC地址：</label>
            <div class="col-sm-8">
                <input name="macAddress" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">OA编号：</label>
            <div class="col-sm-8">
                <input name="oaNumber" class="form-control" type="text">
            </div>
        </div>
    <!--    <div class="form-group">
            <label class="col-sm-3 control-label">工号：</label>
            <div class="col-sm-8">
                <input name="userId" class="form-control" type="text" onblur="findName()">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">使用人：</label>
            <div class="col-sm-8">
                <input name="userName" class="form-control" readonly="true" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">使用部门：</label>
            <div class="col-sm-8">
                <input name="department" class="form-control" readonly type="text">
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">资产归属：</label>
            <div class="col-sm-8">
                <input name="assetOwner" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">资产状态：</label>
            <div class="col-sm-8">
                <select name="assetStatus" class="form-control " onfocus="this.defaultIndex=this.selectedIndex;"
                        onchange="this.selectedIndex=this.defaultIndex;" th:with="type=${@dict.getType('asset_status')}"
                        required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">属性：</label>
            <div class="col-sm-8">
                <select name="assetAttribute" class="form-control "
                        th:with="type=${@dict.getType('asset_attribut')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    var prefix = ctx + "asset/assets"
    $("#form-assets-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-assets-add').serialize());
        }
    };

/*    function findName() {
        // 获取工号输入框的值
        var userId = $("input[name='userId']").val();
        // 发送GET请求到后端获取参数
        $.get("http://172.20.203.11/getoanamedept", {nameid: userId}, function (response) {
            var parse = JSON.parse(response);
            $("input[name='userName']").val();
            $("input[name='department']").val("");
            console.log(response);
            console.log(parse.name);
            if (parse.code == "1") {
                console.log(response.name)
                // 将后端返回的参数设置给使用人输入框
                $("input[name='userName']").val(parse.name);
                $("input[name='department']").val(parse.parent);
            } else {
                $("input[name='userName']").val("没有改名员工");
            }
        });
    }

    // function handleResponse(response) {
    //     // 处理响应数据
    //     function handleResponse(response) {
    //         console.log(response);
    //         if (response.code == 0) {
    //             // 将后端返回的参数设置给使用人输入框
    //             document.getElementById('userName').value = response.data.employeeName;
    //             document.getElementById('department').value = response.data.department;
    //         } else {
    //             document.getElementById('userName').value = response.msg;
    //         }
    //     }
    // }
    //
    // function findName(){
    //     var userId = $("input[name='userId']").val();
    //     var script = document.createElement('script');
    //     script.src = "http://172.20.203.11/getoanamedept?nameid=" + userId + "&callback=handleResponse";
    //     document.head.appendChild(script);
    // }

    // function findName() {
    //     var userId = $("input[name='userId']").val();
    //     // 使用 CORS 进行跨域请求
    //     $.ajax({
    //         url: "http://172.20.203.11/getoanamedept",
    //         type: "GET",
    //         data: { nameid: userId },
    //         xhrFields: {
    //             withCredentials: true
    //         },
    //         crossDomain: true,
    //         success: function(response) {
    //             console.log(response);
    //             if (response.code === 0) {
    //                 $("input[name='userName']").val(response.data.employeeName);
    //                 $("input[name='department']").val(response.data.department);
    //             } else {
    //                 $("input[name='userName']").val(response.msg);
    //             }
    //         },
    //         error: function() {
    //             console.error("CORS request error");
    //         }
    //     });
    // };*/


    $("input[name='purchaseDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='warrantyDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    })
</script>
</body>
</html>